;(function(global) {
  global.sheet = {
    template: `
              <div v-if="isShow" class="sheet-container">
                <div>
                  <div>
                    <div v-for="(item, index) of parts" :key="index">
                      <div class="sheet-type-title">{{ item.catetitle }}</div>
                      <div v-if="where === 1" class="sheet-topic-description">{{ item.cateremark }}</div>
                      <div v-if="where !== 1 || type" class="flex-wrap flex-center-wrap sheet-num-container">
                        <div class="sheet-right-num"><span class="sheet-right-icon"></span>答对 ({{ parts[index].rightNum }})</div>
                        <div class="sheet-wrong-num"><span class="sheet-wrong-icon"></span>答错 ({{ parts[index].wrongNum }})</div>
                      </div>
                      <div v-if="where === 1 && type" class="flex-wrap flex-center-wrap sheet-score-des">
                        <div class="sheet-score-common">满分: {{ parts[index].scoresum }}分</div>
                        <div class="sheet-score-common">得分: {{ parts[index].getScore }}</div>
                        <div class="sheet-score-common">扣分: {{ parts[index].deductScore }}</div>
                        <div>最后得分: {{ parts[index].getScore - parts[index].deductScore }}</div>
                      </div>
                      <div class="sheet-overflow">
                        <div  class="sheet-margin">
                          <div v-for="(value, i) of arrParts[index]"  class="sheet-list">
                            <div class="sheet-topic-num-contianer">
                              <span class="sheet-topic-num" @click="swipeTo(arrParts[index][i].index)" :class="examData[arrParts[index][i].index].historyStyle">
                                {{ arrParts[index][i].index+1 }}
                              </span>
                              <span v-if="examData[arrParts[index][i].index].historyStyle == 'halfRight'" class="sheet-topic-halfRight"></span>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
          `,
    props: ['examData', 'parts', 'where', 'type'],
    components: {},
    data() {
      return {
        isShow: false,
        arrParts: []
      }
    },
    computed: {},
    methods: {
      swipeTo(index) {
        this.$emit('swipeto', index)
      }
    },
    watch: {
      examData(value) {
        if (value) {
          const newValue = this.parts
          let arrParts = []
          let index = 0
          for (let i in newValue) {
            let partsIStem = []
            for (let cateItem of newValue[i].catequesdetails) {
              if (cateItem.typeid !== 5) {
                let topic = {}
                // 把题的id存入
                topic.id = cateItem.id
                topic.index = index
                partsIStem.push(topic)
                index++
              }
              if (cateItem.typeid === 5) {
                // TODO: 此处没存入大题的id
                for (let item of cateItem.crds) {
                  let topic = {}
                  topic.id = item.itemid
                  topic.index = index
                  partsIStem.push(topic)
                  index++
                }
              }
            }
            arrParts.push(partsIStem)
          }
          this.arrParts = arrParts
        }
        this.isShow = true
      }
    },
    created() {
      const newValue = this.parts
      let arrParts = []
      let index = 0
      for (let i in newValue) {
        let partsIStem = []
        for (let cateItem of newValue[i].catequesdetails) {
          if (cateItem.typeid !== 5) {
            let topic = {}
            // 把题的id存入
            topic.id = cateItem.id
            topic.index = index
            partsIStem.push(topic)
            index++
          }
          if (cateItem.typeid === 5) {
            // TODO: 此处没存入大题的id
            for (let item of cateItem.crds) {
              let topic = {}
              topic.id = item.itemid
              topic.index = index
              partsIStem.push(topic)
              index++
            }
          }
        }
        arrParts.push(partsIStem)
      }
      this.arrParts = arrParts
      this.isShow = true
    },
    mounted() {},
    updated() {}
  }
})(window)
